#include <string>
#include <iostream>
#include "contacts.pb.h"

using namespace std;
using namespace contacts;

// demo1：测试序列化和反序列化
int main()
{
    string peopleStr;

    {
        PeopleInfo people;
        people.set_name("Joy");
        people.set_age(20);
        if(!people.SerializeToString(&peopleStr))
        {
            cout << "序列化联系人失败" << endl;
        }
        cout << "序列化联系人成功，结果为：" << peopleStr << endl;
    }

    {
        PeopleInfo people;
        if(!people.ParseFromString(peopleStr))
        {
            cout << "反序列化联系人失败" << endl;
        }
        cout << "反序列联系人成功，name：" << people.name() << " age：" << people.age() << endl;
    }
    
    google::protobuf::ShutdownProtobufLibrary();

    return 0;
}